<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="org.jiangnantaste.domain.Image"%>
<%@page import="org.jiangnantaste.utils.ImageUtil"%>
<%@page import="java.io.ByteArrayInputStream"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>User Home</title>
        <link href="../css/default.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="wrapper">
        <jsp:include page="../include/header.jsp" />
            <!-- end div#header -->
            <div id="page">
                <div id="content">
                    <div id="welcome">
                         <form action="../controller/uploadController" enctype="multipart/form-data" method="post">
                         	<input type="file" name="uploadfile" id="uploadfile"/>
                         	<input type="submit"/>
                         </form>
                         <br/>
                         <br/>
                         <table class="aatable">
                            <tr>
                                <th>Image ID</th>
                                <th>Image Name</th>
                                <th>Path Name</th>
                                <th>Active</th>
                                <th>Picture</th>
                            </tr>
                            <%                                  
                                  List<Image> imList = request.getAttribute("imageList")==null?new ArrayList<Image>():(List<Image>)request.getAttribute("imageList");
                                  
                                  for(int index=0;index < imList.size();index++){
                                	  Image image = imList.get(index);
                                      out.println("<tr>");
                                      out.println("<td>"+image.getImageId()+"</td>");                            
                                      out.println("<td>"+image.getImageName()+"</td>");
                                      out.println("<td>"+image.getPathName()+"</td>");
                                      out.println("<td>"+image.isActive()+"</td>");
                                      ServletContext context = getServletContext();
                                      String currPathName = context.getRealPath("upload");
                                      currPathName += "/" + image.getImageName();
                                      ImageUtil.readBlob(new ByteArrayInputStream(image.getImageData()),currPathName);
                                      out.println("<td><img src=\"../upload/"+ image.getImageName() +"\" width=\"150px\"/></td>");
                                      out.println("</tr>");
                                  }
                            %>
                            
                        </table>
                    </div>
                    <!-- end div#welcome -->
                </div>
                <!-- end div#content -->
                <div id="sidebar">
                    <ul>
                        <%	if("Y".equalsIgnoreCase((String)request.getSession(true).getAttribute("isadmin"))){%>
                    	<jsp:include page="../include/adminnav.jsp"/>
                    	<%} else { %>
                    	<jsp:include page="../include/usernav.jsp"/>
                    	<%} %>
                        <!-- end navigation -->
                        <jsp:include page="../include/updates.jsp"/>
                    </ul>
                </div>
                <!-- end div#sidebar -->
                <div style="clear: both; height: 1px"></div>
            </div>
            <jsp:include page="../include/footer.jsp" />
        </div>
        <!-- end div#wrapper -->
    </body>
</html>
